package cn.ccsu.cecs.student.controller;


import cn.ccsu.cecs.common.utils.PageUtils;
import cn.ccsu.cecs.common.utils.R;
import cn.ccsu.cecs.student.entity.StuClass;
import cn.ccsu.cecs.student.service.IStuClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 班级表 前端控制器
 * </p>
 *
 * @author ccsu-cecs
 * @since 2022-03-05
 */
@RestController
@RequestMapping("/student/stu-class")
public class StuClassController {
    @Autowired
    private IStuClassService stuClassService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = stuClassService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        StuClass stuClass = stuClassService.getById(id);

        return R.ok().put("stuClass", stuClass);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StuClass stuClass) {
        stuClassService.save(stuClass);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StuClass stuClass) {
        stuClassService.updateById(stuClass);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        stuClassService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
